/**
* @file test.cpp
* @brief Split a string according to a delimiter into several parts
* @author wfg
* @version 0.1
* @date 2013-01-04
*/
#include <stdio.h>
#include <string.h>
using namespace std;



/**
* @brief split split a string according to a delimiter
*
* @param msg : 待分割的字符串
* @param delim : 分隔符
* @param count : 分隔符出现的次数
*
* @return 字符串分割后的几部分
*/
char** split(char* msg, char delim, int count)
{
    char** ret = new char* [count];
    int j = 1;
    char* p = msg;
    ret[0] = msg;

    while(*p!='\0') {
        if(*p == delim){
            *p = '\0';
            ret[j++] = p+1;
        }
        p++;
    }
    return ret;
}
char** tst(char* msg, char delim, int cnt)
{
    char** ret = new char* [cnt];
    char* p = msg;
    int j = 1;
    ret[0] = msg;
    while(*p != '\0'){
        if (*p == delim) {
            *p = '\0';
            ret[j++] = p+1;
        }
        p++;
    }
    return ret;
}

/**
* @brief main 主函数
*
* @param argc 参数个数
* @param argv[] 参数
*
* @return 状态
*/
int main(int argc, const char *argv[])
{
    char buf[100]="request:1:123123:3";
    char **p = split(buf, ':', 4);
    int i=0;
    for(; i<4; i++)
    printf("%s ",p[i]);
    printf("\n");
    return 0;
}
